<template>
    <div>
      <el-dialog title="仓库修改"   :visible.sync="dialogFormVisible">
        <el-form :rules="rules"  :model="warehouses" ref="warehouse">
          <el-form-item label="仓库名">
            <el-input v-model="warehouses.warName" placeholder="请输入仓库名"></el-input>
          </el-form-item>
          <el-form-item label="仓库最大库存">
            <el-input-number  v-model="warehouses.warMaxStock" :min="warehouses.warMaxStock"></el-input-number>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible=false">取 消</el-button>
          <el-button type="primary" @click="submitForm('warehouse')">确 定</el-button>
        </div>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        name: "updateWarehouseInfo",
      data(){
          return{
            dialogFormVisible:false,
            warehouse:{id:""},
            warehouses:{},
            rules:{
              warName:[
                { required: true, message: '请输入仓库名', trigger: 'blur' },
              ],
            }
          }
      },
      methods:{
          getdata(){
            var params = new URLSearchParams();
            params.append("id",this.warehouse.id)
            this.$axios.get("warehouseInfo/queyrbyid.action",{params:params}).then(res=>{
              this.warehouses=res.data;
            }).catch(error=>{
              this.$message.error(error)
            })
          },
        submitForm(warehouse){
          this.$refs[warehouse].validate((valid) => {
            if (valid) {
              this.editform()
            } else {
              return false;
            }
          })
        },
        editform(){
          this.$axios.put("warehouseInfo/amendWarehouseInfo.action",this.warehouses).then(res=>{
            if (res.data.code>0){
              this.$message.success(res.data.msg);
              this.$parent.getData()
              this.dialogFormVisible=false

            }else {
              this.$message.error(res.data.msg)
            }
          }).catch(error=>{
            this.$message.error(error)
          })
        }
      }
    }
</script>

<style scoped>

</style>
